package com.ruoyi.web.controller.help;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.help.domain.Evaluate;
import com.ruoyi.help.service.IEvaluateService;
import com.ruoyi.help.vo.EvaluateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 帮扶评价Controller
 *
 * @author ruoyi
 * @date 2023-05-20
 */
@RestController
@RequestMapping("/system/evaluate")
public class EvaluateController extends BaseController {
    @Autowired
    private IEvaluateService evaluateService;

    /**
     * 查询帮扶评价列表
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:list')")
    @GetMapping("/list")
    public TableDataInfo list(Evaluate evaluate) {
        startPage();
        List<Evaluate> list = evaluateService.selectEvaluateList(evaluate);
        return getDataTable(list);
    }

    /**
     * 导出帮扶评价列表
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:export')")
    @Log(title = "帮扶评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Evaluate evaluate) {
        List<Evaluate> list = evaluateService.selectEvaluateList(evaluate);
        ExcelUtil<Evaluate> util = new ExcelUtil<Evaluate>(Evaluate.class);
        util.exportExcel(response, list, "帮扶评价数据");
    }

    /**
     * 获取帮扶评价详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(evaluateService.selectEvaluateById(id));
    }

    /**
     * 新增帮扶评价
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:add')")
    @Log(title = "帮扶评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EvaluateVo evaluateVo) {
        int i = evaluateService.insertEvaluate(evaluateVo);
        if(i == -5){
            return AjaxResult.error("内容为空");
        }
        return toAjax(evaluateService.insertEvaluate(evaluateVo));
    }

    /**
     * 修改帮扶评价
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:edit')")
    @Log(title = "帮扶评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Evaluate evaluate) {
        return toAjax(evaluateService.updateEvaluate(evaluate));
    }

    /**
     * 删除帮扶评价
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:remove')")
    @Log(title = "帮扶评价", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(evaluateService.deleteEvaluateByIds(ids));
    }
}
